<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <table border="">
        <thead>
            <tr>
                <th>用户名</th>
                <th>年龄</th>
                <th>性别</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>jack</td>
                <td>18</td>
                <td>男</td>
            </tr>
            <tr>
                <td>jack</td>
                <td>18</td>
                <td>男</td>
            </tr>
            <tr>
                <td>jack</td>
                <td>18</td>
                <td>男</td>
            </tr>
            <tr>
                <td>jack</td>
                <td>18</td>
                <td>男</td>
            </tr>
        </tbody>
    </table>
    <script>
        var arr = [{
            name: "Jack",
            age: 18,
            gender: "男",
        }, {
            name: "Rose",
            age: 20,
            gender: "女",
        }, {
            name: "Top",
            age: 22,
            gender: "男",
        }, ];
        var otbody = document.getElementsByTagName("tbody")[0];
        console.log(otbody);
        var otr = "";
        for (var i = 0; i < arr.length; i++) {
            if (i % 2 == 0) {
                otr += `<tr
                 style='background:pink'><td>${arr[i].name}</td><td>${arr[i].age}</td><td>${arr[i].gender}</td></tr>`;
            } else {
                otr += `<tr><td>${arr[i].name}</td><td>${arr[i].age}</td><td>${arr[i].gender}</td></tr>`;
            }
        }
        console.log(otr);
        otbody.innerHTML = otr;
    </script>
</body>

</html>